package java_learn.effective_java.createAndDestroy_2;

/**
 * 使用java-beans模式，先调用一个无参构造器创建对象，再调用setter来设置必要参数
 * 创建实例容易，但构造过程中JavaBean可能不一致，需要保证线程安全
 *
 * @Author: 李浩然
 * @Date: 2021/1/25 11:14 上午
 */
public class NutritionFacts_2 {
    private int servingSize = -1;
    private int servings = -1;
    private int calories = 0;
    private int fat = 0;
    private int sodium = 0;
    private int carbohydrate = 0;

    public NutritionFacts_2() {
    }

    public void setServingSize(int servingSize) {
        this.servingSize = servingSize;
    }

    public void setServings(int servings) {
        this.servings = servings;
    }

    public void setCalories(int calories) {
        this.calories = calories;
    }

    public void setFat(int fat) {
        this.fat = fat;
    }

    public void setSodium(int sodium) {
        this.sodium = sodium;
    }

    public void setCarbohydrate(int carbohydrate) {
        this.carbohydrate = carbohydrate;
    }

    public static void main(String[] args) {
        NutritionFacts_2 cocaCola = new NutritionFacts_2();
        cocaCola.setServingSize(240);
        cocaCola.setServings(8);
        cocaCola.setCalories(100);
        cocaCola.setSodium(35);
        cocaCola.setCarbohydrate(27);

    }
}
